/**
 * mkdata管理初始化
 */
var Mkdata = {
    id: "MkdataTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Mkdata.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '代码', field: 'gDm', visible: true, align: 'center', valign: 'middle'},
        {title: '名称', field: 'gName', visible: true, align: 'center', valign: 'middle'},
        {title: '增减', field: 'gZj', visible: true, align: 'center', valign: 'middle'},
        {title: '增减比例(%)', field: 'gZjbl', visible: true, align: 'center', valign: 'middle'},
        {title: '最新价', field: 'gPrice', visible: true, align: 'center', valign: 'middle'},
        {title: '区间涨跌幅(%)', field: 'gJqZdf', visible: true, align: 'center', valign: 'middle'},
        {title: '阳光私募', field: 'gIsYgsmNum', visible: true, align: 'center', valign: 'middle'},
        {title: '个人私募', field: 'gIsGrsmNum', visible: true, align: 'center', valign: 'middle'},
        {title: 'QFILL', field: 'gIsQfillNum', visible: true, align: 'center', valign: 'middle'},
        {title: '基金', field: 'gIsJjNum', visible: true, align: 'center', valign: 'middle'},
        {title: '国家队', field: 'gIsGjdNum', visible: true, align: 'center', valign: 'middle'},
        {title: '企业年金', field: 'gIsQynjNum', visible: true, align: 'center', valign: 'middle'},
        {title: '股东户数统计截止日', field: 'gTime', visible: true, align: 'center', valign: 'middle'},
        {title: '指标日期', field: 'gDate', visible: true, align: 'center', valign: 'middle'},
        {title: '指标类型', field: 'gMkType', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Mkdata.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Mkdata.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加mkdata
 */
Mkdata.openAddMkdata = function () {
    var index = layer.open({
        type: 2,
        title: '添加mkdata',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/mkdata/mkdata_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看mkdata详情
 */
Mkdata.openMkdataDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'mkdata详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/mkdata/mkdata_update/' + Mkdata.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除mkdata
 */
Mkdata.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/mkdata/delete", function (data) {
            Feng.success("删除成功!");
            Mkdata.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("mkdataId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询mkdata列表
 */
Mkdata.search = function () {
    var queryData = {};
    queryData['date'] = $("#date").val();
    queryData['type'] = $("#type").val();
    Mkdata.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Mkdata.initColumn();
    var table = new BSTable(Mkdata.id, "/mkdata/list", defaultColunms);
    table.setPaginationType("server");
    Mkdata.table = table.init();
});
